import { defineStore } from "pinia";
import bar from "@/api/bar";
import type { typeBarList } from "@/api/bar";
import {useUserStore} from "./user";
import pinia from "@/stores";

interface stateType {
  BarList: typeBarList;
  total:number
}

export const useBarStore = defineStore("bar", {
  state: (): stateType => {
    return {
      BarList: [],
      total:0
    };
  },
  actions: {
    async getAllBar(payload?:number) {
      const store = useUserStore(pinia)
      if(store.userInfo._id){
        // 登录状态
        const re = await bar.requestAllBarByToken(payload);
        this.BarList = re.result;
        this.total=re .count
      }else{
        // 未登录状态
        const re = await bar.requestAllBar(payload);
        this.BarList = re.result;
        this.total=re .count
      }
    },
  },
  getters: {},
});
